#!/env/bin/python
# coding:utf-8

from selenium.webdriver.common.action_chains import ActionChains
from functions import date_n,id,name,css,xpath,js,return_driver,open_Url
import time

def search_tickets(from_station,to_station,n):
    driver = return_driver()
    driver.maximize_window()
    open_Url("https://www.ctrip.com/")
    driver.implicitly_wait(10)
    title = driver.title
    if title == "携程旅行网官网:酒店预订,机票预订查询,旅游度假,商旅管理":
        print("pass!")
    else:
        print("{0} != 携程旅行网官网:酒店预订,机票预订查询,旅游度假,商旅管理".format(title))

    from_station = from_station
    to_station = to_station
    tomorow = date_n(n)

    train = id('nav_trains')
    ActionChains(driver).move_to_element(train).perform()
    id("c_ph_train_t").click()
    time.sleep(3)

    id("departCityName").send_keys(from_station)
    time.sleep(1)
    xpath("/html/body/div[14]/div[1]/div[2]").click()
    id("arriveCityName").send_keys(to_station)
    time.sleep(1)
    xpath("/html/body/div[16]/div[1]/div[1]").click()

    js("departDate")
    time.sleep(1)
    id("departDate").clear()
    time.sleep(1)
    #id("departDate").send_keys(tomorow)
    driver.execute_script('document.getElementById("departDate").value="2021-08-30"')
    time.sleep(1)
    #ActionChains(driver).move_by_offset(0, 0).perform()
    css("html body div#searchBoxTemplete.base_top div.base_bd.posre div.s_box div.search_box div.search_form input.searchbtn").click()
    #xpath("/html/body/div[6]/div/div[1]/div[2]/div/input").click()


